<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/12/8
 * Time: 10:31
 */
namespace App\Http\Controllers\Api\V2;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Modules\EntBookType;
use App\Modules\EntBookInfo;
use App\Modules\EntBookImg;
use App\Modules\EntBookSumUp;
use App\Modules\EntBookCollect;
use Validator, DB;
use App\Modules\EntPushMoneyLog;
use App\Modules\EntMemberDRP;
use App\Modules\EntWithdrawMoneyLog;
use App\Modules\EntPayCard;
use App\Modules\EntPosterTemplate;
use App\Modules\EntMobileCode;
use App\Modules\EntMindShare;
use App\Modules\EntReaParLog;
use App\Modules\EntMemberInfo;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\File;

class TestController extends Controller
{
    protected $url = 'http://wxtest.laohoulundao.com';
    protected $url2 = 'http://www.laohoulundao.com';
    protected $bankname = ['中国工商银行', '招商银行', '交通银行', '中国银行', '中国农业银行', '中国邮政储蓄银行', '中国建设银行'];
    protected $address = ['陈亮', '上海市徐汇区龙漕路299号天华信息科技园3B楼8层'];

    public function t1()
    {
        $mobile = '18888824132';
        $key = '92e7b76619d6d81b894600b109a1071c9ab6870a';
        $id = '25';
        $upid = '0';
        $bookidea1 = '2';
        $bookidea2 = '3';
        $bookidea3 = '4';
        $bookidea4 = '5';
        $timestamp = '1483464406';
        $sign = '422563ff2af38d20dd99f458d0f7ca6b';
        $params = ['mobile' => $mobile, 'key' => $key, 'id' => $id, 'upid' => $upid, 'bookidea1' => $bookidea1, 'bookidea2' => $bookidea2, 'bookidea3' => $bookidea3, 'bookidea4' => $bookidea4, 'timestamp' => $timestamp, 'sign' => $sign];
        // $params = ['mobile' => $mobile, 'key' => $key, 'id' => $id, 'timestamp' => $timestamp, 'sign' => $sign];
        ksort($params);
        unset($params['sign']);
        $tmps = array();
        foreach ($params as $k => $v) {
            $tmps[] = $v;
        }
        $string = implode('', $tmps) . 'laohoulundao';
        return view('test/api', ['i' => md5($string)]);
    }

    public function t2()
    {

        $entBookCollect = DB::table('VW_WEB_BookSumUps')->select('BookID', 'FilePath1', 'AddDate', 'BookReview1', 'BookReview2', 'BookReview3', 'BookReview4')->where('MemNumber', '201609300697006402')->get();
        // $k=count($entBookCollect);

        if (count($entBookCollect) == 0) {
            $entBookCollect = [];
        }
        return view('test/api', ['i' => $entBookCollect]);
    }

    public function t3()
    {

        /**
         * 7天的销售情况--开始
         */
        $timeMax = date('Y-m-d', time());
        $timeMin = date("Y-m-d", strtotime("-6 day"));
        $entPushMoneyLog = EntPushMoneyLog::select('AddDate')->where('MemNumber', '201610010276505553')->whereDate('AddDate', '>=', $timeMin)->whereDate('AddDate', '<=', $timeMax)->get();
        $arrayWeekCount = '';
        for ($i = 1; $i < 8; $i++) {
            $arrayWeekCount[date("Y-m-d", strtotime(($i - 7) . " day"))] = 0;
        }
        if (count($entPushMoneyLog) > 0) {
            foreach ($entPushMoneyLog as $key) {
                $addDate = date('Y-m-d', strtotime($key->AddDate));
                if (array_key_exists($addDate, $arrayWeekCount)) {
                    $arrayWeekCount[$addDate] = $arrayWeekCount[$addDate] + 1;
                }
            }
        }
        $timearray = array();
        $maxarray = array();
        foreach ($arrayWeekCount as $k => $v) {
            $timearray[] = $k;
            $maxarray[] = $v;
        }
        /**
         * 7天的销售情况--结束
         */
        return $maxarray;
    }

    public function t4()
    {
        $entWithdrawMoneyLog = EntWithdrawMoneyLog::select('CardNo', 'States', 'WithdrawRemark', 'WithdrawMoney', 'AddDate')->where('MemNumber', '201610010276505553')->orderBy('AddDate', 'desc')->get();
        $entPushMoneyLog = DB::table('vw_web_pushmoneylog')->select('PuMoID', 'MemNumber', 'Scale', 'IsFinish', 'TotalMoney', 'SalesMoney', 'PayMoney', 'MemberType', 'YourName', 'AddDate')->where('MemNumber', '201610010276505553')->where('DeleteMark', '1')->orderBy('AddDate', 'desc')->get();
        return view('test/api', ['i' => $entWithdrawMoneyLog]);
    }

    public function t5()
    {
//        $mobile = '';
//        $key = '';
//        $yourname = '';
//        $banktype = '';
//        $cardno = '';
//        $timestamp = '';
//        $sign = '';
//        $code='';
//        $params = ['mobile' => $mobile, 'key' => $key, 'yourname' => $yourname, 'banktype' => $banktype, 'cardno' => $cardno, 'timestamp' => $timestamp, 'sign' => $sign,'code'=>$code];
//        ksort($params);
        $l = '';
        $entPayCard = EntPayCard::select('PaCaID', 'BankType', 'PayType', 'CardNo')->where('DeleteMark', '1')->where('MemNumber', '201611040118646491')->get();
        if (count($entPayCard) > 0) {
            foreach ($entPayCard as $data) {
                if ($data->PayType == 1) {
                    $data->PayType = $this->bankname[$data->BankType];
                } else {
                    $data->PayType = '支付宝';
                }
            }
        }

        return view('test/api', ['i' => $entPayCard]);
    }

    public function t6()
    {
        //2016120601335701783
        $entMemberDRP = EntMemberDRP::select('FinishMoney', 'SalesMoney', 'DRPID', 'IsRebate', 'MemBalances')->where('MemNumber', '2016112402079636851')->where('DeleteMark', 1)->first();
        $entPushMoneyLog = DB::table('vw_web_pushmoneylog')->select('PuMoID', 'MemNumber', 'Scale', 'IsFinish', 'TotalMoney', 'SalesMoney', 'PayMoney', 'MemberType', 'YourName', 'AddDate')->where('MemNumber', '12016112402079636851')->where('DeleteMark', '1')->orderBy('AddDate', 'desc')->get();
        $entWithdrawMoneyLog = EntWithdrawMoneyLog::select('CardNo', 'States', 'WithdrawRemark', 'WithdrawMoney', 'AddDate')->where('MemNumber', '12016112402079636851')->orderBy('AddDate', 'desc')->get();
        $pushMoneydataList = array();
        $id = 1;
        $str = '';
        $collection = collect($pushMoneydataList);
        //提成记录lt--左上 ln--左下 rt--右上 rn--右下 rc1--中间 rc2--中间
        foreach ($entPushMoneyLog as $pushMoneydata) {
            if ($pushMoneydata->IsFinish == 0) {
                if ($pushMoneydata->Scale == '0.05') {
                    $pushMoneydataList['lt'] = '任务';
                    if ($pushMoneydata->MemberType == 1) {
                        $pushMoneydataList['ln'] = '下线合伙人“' . $pushMoneydata->YourName . '”发展新合伙人';
                    } else {
                        $pushMoneydataList['ln'] = '下线合伙人“' . $pushMoneydata->YourName . '”发展新会员';
                    }
                    $pushMoneydataList['rt'] = '完成金额 ￥' . $pushMoneydata->TotalMoney;
                    $pushMoneydataList['rc1'] = '';
                    $pushMoneydataList['rc2'] = '';
                    $pushMoneydataList['rn'] = $pushMoneydata->AddDate;
                } else {
                    $pushMoneydataList['lt'] = '任务';
                    if ($pushMoneydata->MemberType == 1) {
                        $pushMoneydataList['ln'] = '发展“' . $pushMoneydata->YourName . '”成为了会员';
                    } else {
                        $pushMoneydataList['ln'] = '发展“' . $pushMoneydata->YourName . '”成为了合伙人';
                    }
                    $pushMoneydataList['rt'] = '完成金额 ￥' . $pushMoneydata->TotalMoney;
                    $pushMoneydataList['rc1'] = '';
                    $pushMoneydataList['rc2'] = '';
                    $pushMoneydataList['rn'] = $pushMoneydata->AddDate;
                }
            } else {
                if ($pushMoneydata->Scale == '0.05') {
                    $pushMoneydataList['lt'] = '销售';
                    if ($pushMoneydata->MemberType == 1) {
                        $pushMoneydataList['ln'] = '下线合伙人“' . $pushMoneydata->YourName . '”发展新会员';
                    } else {
                        $pushMoneydataList['ln'] = '下线合伙人' . $pushMoneydata->YourName . '”发展新合伙人';
                    }
                    $pushMoneydataList['rt'] = '提成 +' . $pushMoneydata->TotalMoney;
                    $pushMoneydataList['rc1'] = '';
                    $pushMoneydataList['rc2'] = '';
                    $pushMoneydataList['rn'] = $pushMoneydata->AddDate;
                } else {
                    if ($pushMoneydata->PuMoID == $id) {
                        $u = $pushMoneydata->TotalMoney - $entMemberDRP->SalesMoney;
                        $ul = $pushMoneydata->TotalMoney - $u;
                        $pushMoneydataList['lt'] = '销售';
                        if ($pushMoneydata->MemberType == 1) {
                            $pushMoneydataList['ln'] = '发展“' . $pushMoneydata->YourName . '”成为了会员';
                        } else {
                            $pushMoneydataList['ln'] = '发展“' . $pushMoneydata->YourName . '”成为了合伙人';
                        }
                        $pushMoneydataList['rt'] = '完成金额 +' . $ul;
                        $pushMoneydataList['rc1'] = '提成 +' . $pushMoneydata->PayMoney;
                        $pushMoneydataList['rc2'] = '超出任务' . $pushMoneydata->TotalMoney - $entMemberDRP->SalesMoney;
                        $pushMoneydataList['rn'] = $pushMoneydata->AddDate;
                    } else {
                        $pushMoneydataList['lt'] = '销售';
                        if ($pushMoneydata->MemberType == 1) {
                            $pushMoneydataList['ln'] = '发展“' . $pushMoneydata->YourName . '”成为了会员';
                        } else {
                            $pushMoneydataList['ln'] = '发展“' . $pushMoneydata->YourName . '”成为了合伙人';
                        }
                        $pushMoneydataList['rt'] = '提成 +' . $pushMoneydata->TotalMoney;
                        $pushMoneydataList['rc1'] = '';
                        $pushMoneydataList['rc2'] = '';
                        $pushMoneydataList['rn'] = $pushMoneydata->AddDate;
                    }
                }
            }
            // $str .= collect($pushMoneydataList);
            $collection->push($pushMoneydataList);
        }

        foreach ($entWithdrawMoneyLog as $withdrawMoneydata) {
            if ($withdrawMoneydata->States == 2) {
                $pushMoneydataList['lt'] = '提现失败返还';
                $pushMoneydataList['ln'] = '备注' . $withdrawMoneydata->WithdrawRemark;
                $pushMoneydataList['rt'] = '金额 ' . $withdrawMoneydata->WithdrawMoney;
                $pushMoneydataList['rc1'] = '';
                $pushMoneydataList['rc2'] = '';
                $pushMoneydataList['rn'] = $withdrawMoneydata->AddDate;
                $collection->push($pushMoneydataList);
                $pushMoneydataList['lt'] = '提现[失败]';
                $pushMoneydataList['ln'] = '';
                $pushMoneydataList['rt'] = '- ' . $withdrawMoneydata->WithdrawMoney;
                $pushMoneydataList['rc1'] = '账户' . '*****' . substr($withdrawMoneydata->CardNo, -4);
                $pushMoneydataList['rc2'] = '';
                $pushMoneydataList['rn'] = $withdrawMoneydata->AddDate;
                $collection->push($pushMoneydataList);
            } else {
                if ($withdrawMoneydata->States == 0) {
                    $pushMoneydataList['lt'] = '提现 [处理中]';
                    $pushMoneydataList['ln'] = '';
                    $pushMoneydataList['rt'] = '金额 ' . $withdrawMoneydata->WithdrawMoney;
                    $pushMoneydataList['rc1'] = '账户' . '*****' . substr($withdrawMoneydata->CardNo, -4);
                    $pushMoneydataList['rc2'] = '';
                    $pushMoneydataList['rn'] = $withdrawMoneydata->AddDate;
                } else {
                    $pushMoneydataList['lt'] = '提现 [提现成功]';
                    $pushMoneydataList['ln'] = '';
                    $pushMoneydataList['rt'] = '金额 ' . $withdrawMoneydata->WithdrawMoney;
                    $pushMoneydataList['rc1'] = '账户' . '*****' . substr($withdrawMoneydata->CardNo, -4);
                    $pushMoneydataList['rc2'] = '';
                    $pushMoneydataList['rn'] = $withdrawMoneydata->AddDate;
                }
                $collection->push($pushMoneydataList);
            }

        }
        $sorted = $collection->sortByDesc('rn');
        $ku = $sorted->values()->all();
        // return view('test/api', ['i' =>$entMemberDRP]);
        return response()->json(['message' => $ku, 'code' => '3029']);//会员信息不存在
    }

    public function t7()
    {
        $mobile = '';
        $key = '';
        $securitycode = '';
        $cardno = '';
        $bankname = '';
        $yourname = '';
        $money = '';
        $expressname = '';
        $expressnumber = '';
        $sign = '';
        $timestamp = '';
        $params = ['mobile' => $mobile, 'key' => $key, 'code' => $securitycode, 'cardno' => $cardno, 'bankname' => $bankname, 'yourname' => $yourname, 'money' => $money, 'expressname' => $expressname, 'expressnumber' => $expressnumber, 'timestamp' => $timestamp, 'sign' => $sign];
        ksort($params);
        return view('test/api', ['i' => $params]);
    }

    public function t8()
    {
        $colllist = ['1', '2', '3'];
        //读取所有书籍
        $entBookInfo = DB::table('VW_WEB_BookInfo')->select('BookID', 'IsGratis', 'BookTitle', 'BookDesc', 'FilePath1', 'IsShow', 'DeleteMark', 'ReleaseDate', 'AddDate')->where('IsShow', 1)->where('DeleteMark', 1)->orderBy('SortNumber', 'asc')->orderBy('AddDate', 'desc')->get();
        if (count($entBookInfo) > 0) {
            //程序调整书籍排列顺序0不显示 1显示
            foreach ($entBookInfo as $data) {
                $data->FilePath1 = $this->url . $data->FilePath1;
                if (array_has($colllist, $data->BookID) == true) {
                    $data->IsGratis = 1;
                } else {
                    $data->IsGratis = 0;
                }

                $entBookInfo->merge(['price' => 100, 'discount' => false]);
            }
        }
        return response()->json(['message' => $entBookInfo, 'code' => '3029']);//会员信息不存在
    }

    public function t9()
    {
//        $tempimg = 'http://wxtest.laohoulundao.com/uploads/posttemp/2016110401536697823.png';
//        if (@fopen($tempimg, 'r')) {
//            $defaultImg = 1;
//        } else {
//            $defaultImg = 2;
//        }
        //获取第一个模板
//        $memNumber='201611040967895371';
//        $entPosterTemplate = EntPosterTemplate::select('PosterTitle', 'FilePath1', 'PoTeID')->where('PoTeID', 4)->where('DeleteMark', 1)->where('IsShow', 1)->orderBy('ReleaseDate', 'desc')->first();
//        $FilePath1 = $entPosterTemplate->FilePath1;
//        if ($memNumber != '' && $FilePath1 != '') {
//            $mimg = $FilePath1;
//            $qrimg = '/uploads/qrcode/' . $memNumber . '.png';
//            //海报模板
//            $img1 = imageCreateFromPng($this->url. $mimg);
//            //会员二维码
//            $img2 = imageCreateFromPng($this->url2. $qrimg);
//            imagecopymerge($img1, $img2, 205, 400, 0, 0, imagesx($img2), imagesy($img2), 100);
//            imagepng($img1, $_SERVER['DOCUMENT_ROOT'] . '/uploads/posttemp/' . $memNumber . '.png');
//            imagedestroy($img1);
//            $url = '/uploads/posttemp/' . $memNumber . '.png';
//        }
        return view('test/api', ['i' => 1]);
    }

    public function t10()
    {
        $entMobileCode = EntMobileCode::select('mobile', 'AddDate')->where('ID', '>=', '2737')->where('ID', '<=', '2749')->get();
        return view('test/api', ['i' => $entMobileCode]);
    }

    public function t11()
    {
        $content = '1';
        $contactus = '2';
        $key = '3';
        $sign = '4';
        $timestamp = '5';
        $params = ['contactus' => $contactus, 'content' => $content, 'key' => $key, 'content' => $content, 'timestamp' => $timestamp, 'sign' => $sign];
        ksort($params);
        return view('test/api', ['i' => $params]);
    }

    public function t12()
    {
        Storage::putFileAs('photos', new File('/path/to/photo'), 'photo.jpg');
    }

    public function t13()
    {
        $mobile = '1';
        $name = '2';
        $key = '3';
        $sign = '4';
        $timestamp = '5';
        $params = ['mobile' => $mobile, 'key' => $key, 'name' => $name, 'timestamp' => $timestamp, 'sign' => $sign];
        ksort($params);
        return view('test/api', ['i' => $params]);
    }

    public function t14()
    {
//        $entBookInfo = DB::table('VW_WEB_BookInfo')->select('BookID','(select count(*) from VW_WEB_BookInfo) as GB', 'IsGratis', 'BookTitle', 'BookDesc', 'FilePath1', 'IsShow', 'DeleteMark', 'ReleaseDate', 'AddDate')->where('IsShow', 1)->where('DeleteMark', 1)->orderBy('SortNumber', 'asc')->take(3)->orderBy('AddDate', 'desc')->get();
//        if (count($entBookInfo) > 0) {
//            foreach ($entBookInfo as $data) {
//                $data->GB = 1;
//            }
//
//        }
        $memCount = DB::table('MemberInfo')->where('DeleteMark', '1')->count();
        return view('test/api', ['i' => $memCount]);
    }

    /**
     * 所有书籍
     * @return \Illuminate\Http\JsonResponse
     */
    public function getBookList(Request $request)
    {
        $result = 'no';
        if ($request->isMethod('GET')) {
            if ($request->wantsJson()) {
                $mobile = $request->input('mobile');
                $key = $request->input('key');
                $entMemberInfo = $this->memNumber($mobile, $key);
                if (count($entMemberInfo) > 0) {
                    if ($entMemberInfo->States == 1) {
                        $nowtime = date('Y-m-d h:i:s', time());
                        $endtime = $entMemberInfo->MemEndTime;
                        if (strtotime($nowtime) > strtotime($endtime)) {
                            $i = 1;//会员到期
                        } else {
                            $i = 2; //已付费
                        }
                    } else {
                        $i = 4;//未付费
                    }
                } else {
                    //会员信息读取失败
                    //  return response()->json(['message' => $result, 'code' => '3048']);
                    $i = 3; //未登录只能看免费的
                }
                switch ($i) {
                    case 1:
                        $booklist = array();
                        return response()->json(['message' => 'ok', 'code' => '200', 'booklist' => $booklist, 'memstate' => '1']);
                        break;

                    case 2:

                        //取出该会员所有收藏的书籍
                        $collectList = EntBookCollect::select('BookID')->where('MemNumber', $entMemberInfo->MemNumber)->get();
                        $colllist = array();
                        if (count($collectList) > 0) {
                            foreach ($collectList as $cdata) {
                                $colllist[] = $cdata->BookID;
                            }
                        }

                        //读取所有书籍
                        $entBookInfo = DB::table('VW_WEB_BookInfo')->select('BookID', 'IsGratis', 'BookTitle', 'BookDesc', 'FilePath1', 'IsShow', 'DeleteMark', 'ReleaseDate', 'AddDate')->where('IsShow', 1)->where('DeleteMark', 1)->orderBy('SortNumber', 'asc')->orderBy('AddDate', 'desc')->get();
                        $memTime = $entMemberInfo->AddDate;
                        if (count($entBookInfo) > 0) {
                            //程序调整书籍排列顺序0不显示 1显示
                            foreach ($entBookInfo as $data) {
                                $zero1 = $data->AddDate;
                                $zero2 = $memTime;
                                if (strtotime($zero1) > strtotime($zero2)) {
                                    $data->IsShow = 0;
                                }
                                $data->FilePath1 = $this->url . $data->FilePath1;
                                //是否收藏过该书籍 0-否 1-是--MasterID
                                if (in_array($data->BookID, $colllist) == true) {
                                    $data->MasterID = 1;
                                } else {
                                    $data->MasterID = 0;
                                }
                            }
                        }
                        //1--会员到期不能观看 2已付费可以观看
                        return response()->json(['message' => 'ok', 'code' => '200', 'memstate' => '2', 'booklist' => $entBookInfo]);
                        break;
                    case 3:
                        $booklist = array();
                        return response()->json(['message' => 'ok', 'code' => '200', 'booklist' => $booklist, 'memstate' => '3']);
                        break;
                    case 4:
                        $booklist = array();
                        return response()->json(['message' => 'ok', 'code' => '200', 'booklist' => $booklist, 'memstate' => '4']);
                        break;
                }

            } else {
                return response()->json(['message' => $result, 'code' => '401']);
            }
        } else {
            return response()->json(['message' => $result, 'code' => '404']);
        }
    }

    public function t15()
    {
        $id = '';
        $type = '';
        $companyname = '';
        $tel = '';
        $reaparname = '';
        $reapardesc = '';
        $address = '';
        $mobile = '';
        $key = '';
        $sign = '';
        $timestamp = '';
        $params = ['type' => $type, 'id' => $id, 'companyname' => $companyname, 'tel' => $tel, 'reaparname' => $reaparname, 'reapardesc' => $reapardesc, 'address' => $address, 'mobile' => $mobile, 'key' => $key, 'timestamp' => $timestamp, 'sign' => $sign];

        ksort($params);
        return view('test/api', ['i' => $params]);
    }

    public function t16()
    {
        $id = '';
        $type = '';
        $reaparname = '';
        $reapardesc = '';
        $hobbies = '';
        $mobile = '';
        $key = '';
        $sign = '';
        $timestamp = '';
        $params = ['type' => $type, 'id' => $id, 'reaparname' => $reaparname, 'reapardesc' => $reapardesc, 'hobbies' => $hobbies, 'mobile' => $mobile, 'key' => $key, 'timestamp' => $timestamp, 'sign' => $sign];
        ksort($params);
        return view('test/api', ['i' => $params]);
    }

    public function t17()
    {
        $str = '.1.2.3.4';
        $strID = explode('.', $str);
        foreach ($strID as $k => $v) {
            if ($v == '') {
                unset($strID[$k]);
            }
        }
        $entBookInfo = DB::table('VW_WEB_BookInfo')->select('BookID', 'IsGratis', 'BookTitle', 'BookDesc', 'FilePath1', 'IsShow', 'DeleteMark', 'ReleaseDate', 'AddDate')->where('IsShow', 1)->where('DeleteMark', 1)->whereIn('BookID', $strID)->orderBy('SortNumber', 'asc')->orderBy('AddDate', 'desc')->get();
        return view('test/api', ['i' => $entBookInfo]);
    }

 

    public function t19()
    {
        $id = '';
        $mobile = '';
        $type = ''; //1--同意 2--拒绝
        $key = '';
        $sign = '';
        $timestamp = '';
        $params = ['mobile' => $mobile, 'key' => $key, 'id' => $id, 'type' => $type, 'timestamp' => $timestamp, 'sign' => $sign];
        ksort($params);
        return view('test/api', ['i' => $params]);
    }

    

    public function t21()
    {
        $entBookInfo = EntBookInfo::find(2);
        $entBookInfo['KU'] = 'K';
        return view('test/api', ['i' => $entBookInfo]);
    }

    public function t22()
    {
        $id = '';
        $mobile = '';
        $type = '';
        $parid = '';
        $content = '';
        $key = '';
        $sign = '';
        $timestamp = '';
        $params = ['mobile' => $mobile, 'key' => $key, 'id' => $id, 'type' => $type, 'parid' => $parid, 'content' => $content, 'timestamp' => $timestamp, 'sign' => $sign];
        ksort($params);
        return view('test/api', ['i' => $params]);
    }

    public function t23()
    {
        $params = DB::table('BookInfo')->select('BookID', 'BookTitle')->orderBy('AddDate', 'desc')->simplePaginate(2);
        return view('test/api', ['i' => $params]);
        //return response()->json(['message' => 'ok', 'code' => '200', 'pagelist' => $params->perPage()]);
    }

    public function t24()
    {
        $bookSumup = DB::table('vw_app_booksumup')->select('SumUpID', 'BookReview1', 'BookReview2', 'BookReview3', 'BookReview4', 'AddDate', 'YourName', 'FilePath1', 'SumUpID as zancolor1', 'SumUpID as zancolor2', 'SumUpID as zancolor3', 'SumUpID as zancolor4', 'zansum1', 'zansum2', 'zansum3', 'zansum4', 'commsum1', 'commsum2', 'commsum3', 'commsum4')->where('BookID', $entBookInfo->BookID)->orderBy('AddDate', 'desc')->simplePaginate(6);
        //取出该会员所有收藏的书籍
        $collectList = EntCommZanLog::select('ZanID', 'Type', 'CommID')->where('MemNumber', '201610120950458705')->get();

        foreach ($bookSumup as $data) {
            if (count($collectList) > 0) {
                foreach ($collectList as $zandata) {
                    if ($zandata->CommID == $data->SumUpID) {
                        switch ($zandata->Type) {
                            case 1:
                                $data->zancolor1 = 1;
                                break;
                            case 2:
                                $data->zancolor2 = 1;
                                break;
                            case 3:
                                $data->zancolor3 = 1;
                                break;
                            case 4:
                                $data->zancolor4 = 1;
                                break;
                        }
                    } else {
                        $data->zancolor1 = 0;
                        $data->zancolor2 = 0;
                        $data->zancolor3 = 0;
                        $data->zancolor4 = 0;
                    }
                }
            } else {
                $data->zancolor1 = 0;
                $data->zancolor2 = 0;
                $data->zancolor3 = 0;
                $data->zancolor4 = 0;
            }
        }
        return view('test/api', ['i' => $bookSumup]);
    }

    public function t25()
    {
        $cardno = '1';
        $securitycode = '2';
        $mobile = '3';
        $key = '4';
        $sign = 'aaaa';
        $timestamp = '5';
        $params = ['mobile' => $mobile, 'key' => $key, 'cardno' => $cardno, 'code' => $securitycode, 'timestamp' => $timestamp, 'sign' => $sign];
        ksort($params);
        $sign = array_key_exists('sign', $params) ? $params['sign'] : '';

        if (empty($sign)) {
            return array('status' => false, 'code' => '1006');
        }
        unset($params['sign']);

        return view('test/api', ['i' => $params]);
    }

    public function t26()
    {
        // "mobile":"18888824132","key":"92e7b76619d6d81b894600b109a1071c9ab6870a","id":"1083","type":"1","parid":"6","content":"Aqwe123123","timestamp":"1483443597","sign":"278cec87ac67b64029cc84a654dd6591"
        $content = 'Aqwe123123';
        $parid = "6";
        $type = '1';
        $id = '1083';
        $mobile = '18888824132';
        $key = '92e7b76619d6d81b894600b109a1071c9ab6870a';
        $sign = '278cec87ac67b64029cc84a654dd6591';
        $timestamp = '1483443597';

        $params = ['mobile' => $mobile, 'key' => $key, 'content' => $content, 'parid' => $parid, 'type' => $type, 'id' => $id, 'timestamp' => $timestamp, 'sign' => $sign];
        ksort($params);
        unset($params['sign']);
        $tmps = array();
        foreach ($params as $k => $v) {
            $tmps[] = $v;
        }
        $string = implode('', $tmps) . 'laohoulundao';
        //return $string;
        return md5($string);
    }

    public function t27()
    {
        $planstr = '1_100|2_300';
        $typeOne = '';
        $moneyOne = '';
        $typeTwo = '';
        $moneyTwo = '';
        if (strstr($planstr, '|') == true) {
            $arrayplanstr = explode('|', $planstr);
            foreach ($arrayplanstr as $k => $v) {
                $arrayplanstrTwo = explode('_', $v);
                    switch ($k) {
                        case 0:
                            $typeOne = $arrayplanstrTwo[0];
                            $moneyOne = $arrayplanstrTwo[1];
                            break;
                        case 1:
                            $typeTwo = $arrayplanstrTwo[0];
                            $moneyTwo = $arrayplanstrTwo[1];
                            break;
                    }
            }
        }
        return $typeOne . '_' . $moneyOne . '_' . $typeTwo . '_' . $moneyTwo;
    }
    public function t28(){
        $id = 10;
        $planstr ='1_30|2_100';
        $mobile ='13761325105';
        $key = 'a05705733c45dbd3b77df374299f67dc16ba4551';
        $sign = '2dd632644ac538a6b056a790d6afa995';
        $timestamp = '1231546721';
        $params = ['mobile' => $mobile, 'key' => $key, 'id' => $id, 'planstr' => $planstr, 'timestamp' => $timestamp, 'sign' => $sign];
        ksort($params);
        unset($params['sign']);
        $tmps = array();
        foreach ($params as $k => $v) {
            $tmps[] = $v;
        }
        $string = implode('', $tmps) . 'laohoulundao';
        //return $string;
        DB::table('MemberMoney')->insert(['ReaParID' => 1, 'StudyMoney' => 0, 'MemNumber' => '1', 'ReleaseDate' => date('Y-m-d H:i:s', time()), 'AddDate' => date('Y-m-d H:i:s', time())]);
        return md5($string);
    }



    //微表情测试
    public function biaoqing(Request $request){
        $name = $request->input('name');
        $name = userTextEncode($name);
        $data = ['name'=>$name];
        DB::table('www_zhangweixi')->insert($data);
        $info = DB::table('www_zhangweixi')->orderBy('id','desc')->first();
        $name1 = $info->name;
        $name1 = userTextDecode($name1);
        return view('test/biaoqing',["name"=>$name,'name1'=>$name1]);
    }
}